
package com.example.smartcity.ui.dashboard;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;

import com.example.smartcity.R;
import com.example.smartcity.ui.dashboard.Fragment.AccountMangerFragment;
import com.example.smartcity.ui.dashboard.Fragment.autoGitFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class LifeGit extends AppCompatActivity {

    private BottomNavigationView bottomNavigationView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_life_git);
        bottomNavigationView = findViewById(R.id.bottomMenu);
        initView();
    }
    public void setBack(View view){
        this.finish();
    }

    public void initView(){
        replaceFragment(new autoGitFragment());

        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.autoGit:
                        replaceFragment(new autoGitFragment());
                        return true;
                    case R.id.MangerAccount:
                        replaceFragment(new AccountMangerFragment());
                        return  true;
                }
                return false;
            }
        });
    }

    //替换界面
    public void replaceFragment(Fragment fragment){
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.frameLayout,fragment);
        transaction.commit();
    }
}